<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<body onload="javascript:pay();">
<script type="text/javascript">
    function pay(){
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }
    }
    function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId" : "${appid}",     //公众号名称，由商户传入
                "timeStamp": "${timeStamp}",         //时间戳，自1970年以来的秒数
                "nonceStr" : "${nonceStr}", //随机串
                "package" : "${packageValue}",
                "signType" : "MD5",         //微信签名方式:
                "paySign" : "${paySign}"    //微信签名
            },function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok"){
                    alert("微信支付成功!");
                    window.history.back(-1);
                }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                    alert("用户取消支付!");
                    window.history.back(-1);
                }else{
                    alert("支付失败!");
                    window.history.back(-1);
                }
            });
    }
</script>
</body>
</html>
